# Table 8: Concurrent Elections and Referendums


# 1. Load Packages ----

library(lfe)
library(stargazer)
library(tidyverse)

# 2. Read in Data ----

load(file = "df_voxit_individual_props.RData")

load(file = "df_concurrent_elections.RData")

load(file = "df_voxit_individual_analysis.RData")

# 3. Data Preparation ----
# Turnout
ref_turn <- voxit_individual %>%
  group_by(canton_id, datum_merge) %>%
  summarise(turnout_admin = max(turnout_admin),
            concurrent_e = max(concurrent))

# Selective Abstention
ref_sabst <- voxit_propositions %>%
  group_by(canton_id, datum_merge, anr) %>%
  summarise(sabst_admin = max(sabst_admin),
            concurrent_e = max(concurrent))

# 4. Regressions ----
# Elections
e_turn <- felm(formula = turnout ~ concurrent | canton + period |
                 0 | canton, data = concurrent_elections)
summary(e_turn)


e_abst <- felm(formula = ballots_empty_share ~ concurrent | canton + period |
                 0 | canton, data = concurrent_elections)
summary(e_abst)

# Referendums
r_turn <- felm(formula = turnout_admin ~ concurrent_e | canton_id + datum_merge |
                 0 | canton_id, data = ref_turn)
summary(r_turn)

r_abst <- felm(formula = sabst_admin ~ concurrent_e | canton_id + datum_merge |
                 0 | canton_id, data = ref_sabst)
summary(r_abst)


# 5. Regression Table ----
stargazer(e_turn, e_abst, r_turn, r_abst,
          type = "latex",
          star.cutoffs = c(0.1, 0.05, 0.01),
          star.char = c("*", "**", "***"),
          summary = T,
          covariate.labels = c("Concurrent referendums", "Concurrent elections"),
          df = F,
          column.labels = c("Election", "Referendum"),
          dep.var.labels = c("Turnout", "Selective abstention",
                             "Turnout", "Selective abstention"),
          add.lines = list(c("Aggregation level", "Election", "Election",
                             "Voting day", "Proposition")),
          column.separate = c(2,2),
          float = F, 
          omit.table.layout ="n",
          keep.stat = c("n"),
          out = "Table8.tex")





























